/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	ComponentNativeScript.cpp
*
*	Comments	-	See ComponentNativeScript.h
*
**************************************************************************************/
#include "../Include/ComponentNativeScript.h"

namespace Pulse
{
	_INativeScript::_INativeScript( ComponentNativeScript *pComponentOwner )
		: m_pScriptComponent( pComponentOwner )
	{

	}


	ComponentNativeScript::ComponentNativeScript( Actor *pOwner )
		: IComponent( pOwner ), m_pNativeScript( PSX_NULL )
	{

	}

	ComponentNativeScript::~ComponentNativeScript( void )
	{
		RemoveScript();
	}

	EErrorCode::Type ComponentNativeScript::Initialize( XMLElementPtr pElem )
	{
		//// Call custom script initialize
		//EErrorCode::Type retCode = OnScriptInitialize();
		//
		//if ( retCode != EErrorCode::OKAY )
		//{
		//	PSX_PushWarning( "Failed to initialize script." );
		//	return retCode;
		//}
		
		return EErrorCode::OKAY;
	}

	void ComponentNativeScript::Update( FLOAT dt )
	{
		// NOTE: Do some other stuff


		// Call custom script update
		if ( m_pNativeScript )
			m_pNativeScript->OnScriptUpdate( dt );
	}

	void ComponentNativeScript::RemoveScript( void )
	{
		if ( m_pNativeScript )
		{
			m_pNativeScript->OnScriptDestroy();
			FactoryNativeScript::GetInstance()->Delete( m_pNativeScript );
			m_pNativeScript = PSX_NULL;
		}
	}

}